// Leon Yu's Utility Extensions (YUX)
// Centralized compatibility verification

// Define yux object
if (typeof yux === 'undefined') var yux = {};

// Compatibility tests
yux.compat = 
{
	// Test a feature
	// Returns true if pass the tests, false otherwise. 
	assert : function (condition, string)
	{
		if (!condition)
		{
			alert('Aassertion failed:\n\n' + string);
			return false;
		}
		return true;
	}
}

// Error handling
yux.errors =
{
	errorCount : 0,

	suppressionHandler : function ()
	{
		yux.errors.errorCount++;
		return true;
	},

	// Start error suppression using onerror
	// Originally designed for IE4 syntax errors, but now works for other browsers.
	// IE 4 gives user ugly syntax error when it encounters try/catch block even if error prompt is disabled.
	suppress : function ()
	{
		// W3C/IE5+ event registration does not appear to catch all errors
		window.onerror = yux.errors.suppressionHandler;
	},

	// Stop error suppression
	// Unhook window.onerror, return number of errors suppressed. 
	unsuppress : function ()
	{
		window.onerror = null;

		var returnValue = yux.errors.errorCount;
		yux.errors.errorCount = 0;
		return returnValue;
	}
}

// start error suppression immediately.
yux.errors.suppress();

if (!window.console)
{
	window.console =
	{
		assert : function () {},
		clear : function () {},
		error : function () {},
		info : function () {},
		log : function () {},
		warn : function () {}
	}
}
